﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Workflow2211A.Consol.Data;
using Workflow2211A.Consol.Steps;
using WorkflowCore.Interface;

namespace Workflow2211A.Consol.Workflows
{
    //设置一个随机数 0-> 重新执行，1->结束
    //并且需要统计循环的次数
    public class LoopWorkflow : IWorkflow<LoopData>
    {
        public string Id => nameof(LoopWorkflow);

        public int Version => 1;

        public void Build(IWorkflowBuilder<LoopData> builder)
        {
            builder.StartWith<StartStep>()
                   .Then<LoopStep>(rand =>
                   {
                       rand.Input(step => step.LoopCount, data => data.LoopCount);
                       rand.Output(data => data.LoopCount, step => step.LoopCount);

                       rand.When(0).Then(rand)
                       .When(1).Then<EndStep>();
                   });
        }
    }
}
